package arong.com.mvpproject;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;

import java.util.List;

import arong.com.mvpproject.mvpPresenter.MvpPresenter;
import arong.com.mvpproject.mvpView.MvpView;
import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements MvpView, AdapterView.OnItemClickListener {
    MvpPresenter mvpPresenter;
    ListView listView;
    ProgressBar progressBar;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView=(ListView) findViewById(R.id.listView);
        progressBar=(ProgressBar)findViewById(R.id.progressBar);
        listView.setOnItemClickListener(this);
        mvpPresenter = new MvpPresenter(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mvpPresenter.onResume();

    }

    @Override
    public void loadingView() {
        progressBar.setVisibility(View.VISIBLE);
    }

    @Override
    public void dismissView() {
        progressBar.setVisibility(View.GONE);

    }

    @Override
    public void setListData(List<String> list) {
        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1, list);
        listView.setAdapter(adapter);
    }

    @Override
    public void showMessage(String msg) {
        Toast.makeText(this, "msg", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        mvpPresenter.onItemClick(position);
    }
}
